import 'dart:convert';
import 'dart:io';

import 'package:flustars/flustars.dart';
import 'package:management/utils/http_utils.dart';
import 'package:management/utils/log_utils.dart';

class ParkApi {
  ///车场云接口域名
  static const String park_host = "https://www.cytingchechang.com";

  ///车场云登录接口
  static const String url_login = "/pb/pv/v1/login";

  ///车场云登录请求携带的数据 用户名和密码
  static const Map park_loginBody = {
    "userName": "btTest",
    "userPassword": "123456"
  };

  ///小程序开启畅盈一楼大门接口
  static const String cyGateOpen = "/os/v1/miniProgram/openGate/free";
  static const String cyGateOpen2 =
      "https://www.cytingchechang.com/os/v1/tcpToken/openDoor/6741";

  ///保存车场云登录成功后返回的token
  static String? parkToken;

  ///车场云登录成功后返回的userId
  ///用于控制车场闸门
  static int parkUserId = 0;

  ///static String reLogin = "pages/login/index";

  ///登录车场云
  static Future loginParkCloud() async {
    var response = await HttpUtil.client.post(
      Uri.parse(ParkApi.park_host + ParkApi.url_login),
      headers: const {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
      },
      body: JsonUtil.encodeObj(ParkApi.park_loginBody),
    );

    if (response.statusCode == HttpStatus.ok) {
      var convert = JsonDecoder().convert(response.body);
      parkToken = convert["data"]["token"];
      parkUserId = convert["data"]["id"];
    }

    MyLog.d("loginParkCloud response: ${response.body}");
  }

  ///测试火峰相机MAC 9070660A6CA7  7069
  ///
}

class FaceApi {
  ///人脸云登录接口
  static const String face_url_login =
      "http://cyai.cytingchechang.com/pb/pv/v1/login";

  ///人脸云登录成功后返回的userId
  static int faceUserId = 0;

  ///保存人脸云登录成功后返回的token
  ///用于控制人脸机继电器
  static String? faceToken;

  ///测试相机 x26 MAC: C2:62:33:FF:64:0C 版本210425-1.5.3RC1-kaer-d
  static const String test_face_camera_gate_open =
      "http://cyai.cytingchechang.com/os/v1/ai/aiApp/openRelay/24155/4888";
//测试相机 x28  MAC: 00:2A:2A:70:00:95 24459/4888
//测试相机 x26  MAC: FA:20:6E:95:81:0A 23845/4888
//MAC 2A-70-01-76 24604/9798
//0E:8A:5E:3C:26:46
//113.88.147.154

}
